import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/reset.css";
import { createPinia } from "pinia";
const pinia = createPinia();
createApp(App).use(router).use(Antd).use(pinia).mount("#app");

import { useLoginUserStore } from "@/store/useLoginUserStore";
router.beforeEach(async (to, from, next) => {
  const loginUserStore = useLoginUserStore();
  await loginUserStore.fetchLoginUser();
  // 如果尚未加载过用户信息，则拉取一次
  if (!loginUserStore.loginUser && !loginUserStore.loading) {
    await loginUserStore.fetchLoginUser();
  }

  next(); // 继续导航
});
